//
//  SearchScreenTableViewCell.m
//  TheRoadAD
//
//  Created by 宁宁 on 16/8/25.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "SearchScreenTableViewCell.h"



#define ButtonWidth 80

@implementation SearchScreenTableViewCell
{
    NSMutableArray *_btnArray;

    NSArray *_conditionArray;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    _btnArray = [NSMutableArray array];
}

- (void)setScrollViewWithConditionArray:(NSArray *)conditionArray andTitle:(NSString *)title{
    _title.text = title;
    //实际尺寸
    _scrollView.contentSize = CGSizeMake(ButtonWidth * [conditionArray count], 35);
//        scrollView.delegate = self;
    _scrollView.showsHorizontalScrollIndicator = NO;
    
    for (int j = 0; j < [conditionArray count]; j++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(8 + ButtonWidth * j, 6, ButtonWidth - 16, 23);
        [button setTitle:conditionArray[j] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont fontWithName:AppFont size:12];
        button.layer.borderWidth = 1;
        button.layer.borderColor = [UIColor blackColor].CGColor;
        button.layer.cornerRadius = 5;
        [button addTarget:self
                   action:@selector(conditionClick:) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:button];
        [_btnArray addObject:button];
    }
    
    _conditionArray = conditionArray;
}

- (void)conditionClick:(UIButton *)sender{
    for (int i = 0; i < _btnArray.count; i++) {
        UIButton *button = _btnArray[i];
        button.layer.borderColor = [UIColor blackColor].CGColor;
        if (button == sender) {
            button.layer.borderColor = UIColorFromRGB(0x03DACE).CGColor;
            _screen(_conditionArray[i]);
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
